<?php
/**
 * 添加新产品页面
 * thankwsx
 */
?>
<style>#form_add_product{
	margin:4px;
	padding:10px;
	background:#f7f7f7;
	border:1px solid #d5d5d5;
}
#form_add_product label {
	text-align:right;
	padding-right:20px;
	float:left;
	width:140px;
}
#form_add_product input,#form_add_product textarea {
	border-left:1px solid #666;
	border-top:1px solid #666;
	border-bottom:1px solid #ccc;
	border-right:1px solid #ccc;
}
#form_add_product  div {
	margin:10px 0;
}
#subclass span {
	padding:4px;
}
</style>
<script>
function selthisclass(obj) {
	$("#selclass").val($(obj).text());
}
function addnewclass(obj) {
	$("#newclass").remove();
	$(obj).after("<div id='newclass' ></div>");
	$("#newclass").html("<input type='text' name='class_name' id='class_name' value='' /><input type='button' value='添加' onclick='addclass();' />");
}
function addclass() {
	$.post("?controller=productclasses&action=addclass",{"class_name":$("#class_name").val(),"pcid":$("#classid").val(),"time":Math.random()},function(htmlcode){
		if(htmlcode==true) {
			$('#subclass').append("<span onclick='selthisclass(this);'>"+$("#class_name").val()+"</span>");
			$("#selclass").val($("#class_name").val());
			$("#newclass").remove();
		} else {
			alert(htmlcode);
		}
	});
}

</script>
<form id="test_form" name="test_form"  enctype="multipart/form-data"  action="?controller=Products&action=addproduct" target='ifmAction' method="post">
	<div id="form_add_product" style='text-align:left;'>
	<div><label>目前所处分类：</label><span onclick='selthisclass(this);'><?php echo $class['class_name'];?></span></p>
	<div><label>已有小分类：</label>
	<div id='subclass'>
	<?php
	foreach($subclasses as $subclass) {
		echo "<span onclick='selthisclass(this);'>".$subclass['class_name']."</span>";
	}
	?>
	</div>
		<input value='添加里面没有的分类' type='button' onclick='addnewclass(this);' style='bottom:0;right:0;' />
		所选分类：<input type='text' id="selclass" name='selclass' value='<?php echo $class['class_name'];?>' />
		<input type='hidden' name='classid' id="classid" value='<?php echo $class['pcid'];?>' />
	</div>
	<div>
		<label>产品名称：</label>
		<input type='text' name='product_name' id='product_name' />
	</div>
	<div>
		<label>产品描述：</label>
		<textarea name='product_desc' id='product_desc' cols='50' rows='10'></textarea>
	</div>
	<div>
		<label>资源文件：</label> <a href="javascript:add_file();">添加文件</a>
		<div id="uploadfile">
		<?php
		//<input type='file' name='product_media' id='product_media' style='' />
		?>
		</div>
	</div>
	<div>
		<label>Tags：</label><input type='text' name='tags' id='tags' value='' />
		<div></div>
	</div>
	<div>
		<input type='button' onclick="a();" id='submitBtn' value='提交' />
	</div>
	</div>
</form>
<iframe name='ifmAction' height='300' width='600' />
<script type="text/javascript">
</script>